Crate unc_jsonrpc_client

source ·
Expand description

Lower-level API for interfacing with the unc Protocol via JSONRPC.

§Layout

Each one the valid public JSON RPC methods are pre-defined in specialized modules within the methods module.

Inside every method module (e.g methods::query) there’s;

Calling a constructed request on a client returns with the response and error types for that method.

§Examples

  1. Request server status from testnet RPC

    use unc_jsonrpc_client::{methods, JsonRpcClient};
    
    let client = JsonRpcClient::connect("https://rpc.testnet.unc.org");
    
    let request = methods::status::RpcStatusRequest; // no params
    
    // call a method on the server via the connected client
    let server_status = client.call(request).await?;
    
    println!("{:?}", server_status);
  2. Query transaction status from mainnet RPC

    use unc_jsonrpc_client::{methods, JsonRpcClient};
    use unc_jsonrpc_primitives::types::transactions::TransactionInfo;
    
    let client = JsonRpcClient::connect("https://archival-rpc.mainnet.unc.org");
    
    let tx_status_request = methods::tx::RpcTransactionStatusRequest {
        transaction_info: TransactionInfo::TransactionId {
            tx_hash: "9FtHUFBQsZ2MG77K3x3MJ9wjX3UT8zE1TczCrhZEcG8U".parse()?,
            sender_account_id: "miraclx.unc".parse()?,
        },
    };
    
    let tx_status = client.call(tx_status_request).await?;
    
    println!("{:?}", tx_status);

Modules§

  • Helpers for client authentication.
  • Error types.
  • Client headers.
  • This module contains all the RPC methods.

Structs§

Constants§

Traits§

Type Aliases§